package com.zbest.zpay.gw.processor;

import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.zbest.zpay.gw.assemble.MessageAssembleManager;
import com.zbest.zpay.gw.dispatch.MessageDispatcherManager;
import com.zbest.zpay.gw.model.MessageContext;
import com.zbest.zpay.gw.parser.MessageParserManager;

@Service("messageReceive")
public class MessageReceiveImpl implements MessageProcessor {

    @Resource
    private MessageAssembleManager   messageAssembleManager;

    @Resource
    private MessageParserManager     messageParserManager;

    @Resource
    private MessageDispatcherManager messageDispatcherManager;

    @Override
    public MessageContext process(String channelId, Map<String, Object> data) {

        // 1.解析收到的报文
        MessageContext context = new MessageContext();
        context.setChannelId(channelId);
        context.setRequestData(data);
        messageParserManager.parse(context);

        // 2.回调对应的业务系统
        messageDispatcherManager.send(context);

        // 3.组装返回结果
        messageAssembleManager.assemble(context);

        return context;

    }

}
